package com.xinjun.kingstar.ui.fragments.login;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;

import com.hengjun.kingstar.sdk.base.BasePresenter;
import com.hengjun.kingstar.sdk.base.fragment.BaseMVPCompatFragment;
import com.xinjun.kingstar.R;
import com.xinjun.kingstar.contract.login.LoginContract;
import com.xinjun.kingstar.presenter.login.LoginPresenter;
import com.xinjun.kingstar.ui.fragments.home.child.HomeFragment;

/**
 * Created by SC-02 on 2018/9/19.
 * 子LoginFragment
 * 1继承BaseMVPCompatFragment
 * 2必须实现契约类里面的view接口并且重写对应的方法（该fragment有请求就必须实现，重写，不然会报错）
 */

public class LoginFragment extends BaseMVPCompatFragment<LoginContract.LoginPresenter> implements LoginContract.ILoginView {
    private ImageView imageView ;
    private EditText editText ;
    boolean eyeOpen = false ;
    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return LoginPresenter.newInstance();
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_login;
    }

    @Override
    public void initUI(View view, @Nullable Bundle savedInstanceState) {

        imageView = getActivity().findViewById(R.id.hide_et);
        editText =  getActivity().findViewById(R.id.pwd_et);
        imageView.setFocusable(true);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (eyeOpen) {
                    //密码
                    editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
                    imageView.setImageResource(R.drawable.login_icon_hide);
                    eyeOpen = false;
                } else {
                    //明文
                    editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                    imageView.setImageResource(R.drawable.login_icon_hide);
                    eyeOpen = true;
                }
            }
        });
    }
    /**
     * 提供实例化对象
     *
     * @return
     */
    public static LoginFragment newInstance() {
        return new LoginFragment();
    }
}
